#!/usr/bin/python
# -*- coding:utf-8 -*-
import sys
import urllib2
import threading
import Queue

domains   = file(r'E:\Git\PythonStudy\code\domains.txt').readlines()
paths     = file(r'E:\Git\PythonStudy\code\dirs.txt').readlines()
url_queue = Queue.Queue()

def check_url(url_target):
    try:                                           #异常检测模式
        res = urllib2.urlopen(url_target)                 #请求指定URL
        if res.msg == 'OK':                        #如果返回正常
            if 'phpinfo()' in res.read():          #读取网页内容，判断有无关键字
                return True
    except:
        pass
    return False

def init_url_queue():
    for domain in domains:
        for path in paths:
            url    = 'http://' + domain.replace('\n','') + path.replace('\n', '')
            url_queue.put(url)

def scan(i):
    while True:
        url = url_queue.get()
        if check_url(url):
            print i,'!!!!!!!!!!!!!!!!:',url,'************'
        else:
            print i,'...', url


init_url_queue()

for i in range(0,5):
    t = threading.Thread(target=scan, args=(i,))
    t.start()